//
//  BQYLDownView.m
//  BeeQuick
//
//  Created by 杨雷 on 2016/11/22.
//  Copyright © 2016年 six_group. All rights reserved.
//

#import "BQYLDownView.h"
#import "BQMyCarTool.h"


@interface BQYLDownView ()
@property (weak, nonatomic) IBOutlet UIButton *buyCarBtn;

@property (weak, nonatomic) IBOutlet UIButton *minusBtn;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;

@property (weak, nonatomic) IBOutlet UIButton *addBtn;
@property (weak, nonatomic) IBOutlet UILabel *buycount;


@end




@implementation BQYLDownView


//减号事件
- (IBAction)minusClickAction:(UIButton *)sender
{
    
    if (_model.buyCount > 0)
    {
        
//        _model.buyCount--;
        [myCar removeGoods:_model];
        
        _countLabel.text = @(_model.buyCount).description;
        
        //购物车总数量
        _buycount.text = @([myCar showTotalNum]).description;
    }
    //数量为0时countbtn隐藏
    _buycount.hidden = ([myCar showTotalNum] == 0);
}

//加号事件
- (IBAction)addClickAction:(UIButton *)sender
{
//    _model.buyCount++;
    
    [myCar addGoods:_model];
    
     self.model.Selected = YES;
    
    _countLabel.text = @(_model.buyCount).description;
    
    //购物车总数量
    _buycount.text = @([myCar showTotalNum]).description;
    
    _buycount.hidden = NO;
}

//购物车按钮付款
- (IBAction)payClickAction:(UIButton *)sender
{
    if ([_delegate respondsToSelector:@selector(downView:withSelectedModel:)])
    {
        [_delegate downView:self withSelectedModel:_model];
    }
    
}

//给控件赋值
- (void)setModel:(BQHomeGoodModel *)model
{
    _model = model;
    
    
    //本类商品数量
    _countLabel.text = @(model.buyCount).description;
    
    //数量为0时countbtn隐藏
    _buycount.hidden = ([myCar showTotalNum] == 0);
    

    //购物车总数量
    _buycount.text = @([myCar showTotalNum]).description;
    
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    _buycount.layer.cornerRadius = 7.5;
    _buycount.clipsToBounds = YES;
    
    //本类商品数量
    _countLabel.text = @(_model.buyCount).description;

    
    //数量为0时countbtn隐藏
    _buycount.hidden = ([myCar showTotalNum] == 0);
    
    
    //购物车总数量
    _buycount.text = @([myCar showTotalNum]).description;
    
    
    
    [_buyCarBtn addTarget:self action:@selector(jumpToBuycar:) forControlEvents:UIControlEventTouchUpInside];

}

- (void)jumpToBuycar:(UIButton *)sender
{
    
    //发通知别人别人跳转
    [[NSNotificationCenter defaultCenter] postNotificationName:@"jumpToBuyCar" object:self];
    
    
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
